package com.henry.response;

import com.henry.constant.HttpStatus;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一响应体
 * @author Liu Hanlin
 * @create 2025-01-24 14:05
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseBody<T> implements Serializable {

    /** 统一返回结果响应码 */
    private Integer code;

    /** 统一返回消息 */
    private String message;

    /** 统一返回结果体 */
    private T data;

    public ResponseBody(Integer code, String message) {
    }

    public static <T> ResponseBody<T> success(){
        return new ResponseBody<T>(HttpStatus.SUCCESS, "success");
    }

    public static <T> ResponseBody<T> success(T data){
        return new ResponseBody<T>(HttpStatus.SUCCESS, "success", data);
    }

    public static <T> ResponseBody<T> fail(String message){
        return new ResponseBody<T>(HttpStatus.ERROR, message);
    }


    public static <T> Boolean isSuccess(ResponseBody<T> responseBody) {
        return responseBody != null && HttpStatus.SUCCESS == responseBody.getCode();

    }

}
